/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import business.RegisterMember;
import business.ShowMember;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import data.ConnectionManager;
import data.RegisterMemberDBase;
import javax.servlet.*;
import javax.servlet.ServletException;

import javax.servlet.http.*;

/**
 *
 * @author User
 */
public class UpdateMember1Servlet extends HttpServlet {

    RegisterMemberDBase dbobject = new RegisterMemberDBase();

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        ResultSet rs = null;
        String idEdit = request.getParameter("ed_id");
//        System.out.println(idEdit);
// res.setContentType("text/html");
        PrintWriter out = response.getWriter();
        Connection conn = null;
//using movie_resolved view

        String connectionURL = "jdbc:mysql://localhost:3306/cemilansehat";
        Connection connection = null;

        response.setContentType("text/html");
        try {

//
            Class.forName("com.mysql.jdbc.Driver");
            // Get a Connection to the database
            connection = DriverManager.getConnection(connectionURL, "root", "");
            //Select the data from the database
            String sql = "select * from member where id_member='" + idEdit + "'";
            Statement s = connection.createStatement();
            s.executeQuery(sql);
            rs = s.getResultSet();
            if (rs.next()) {
                ShowMember member = new ShowMember(rs);
                member.setId(rs.getString(1));
                member.setNama(rs.getString(2));
                member.setJk(rs.getString(3));
                member.setEmail(rs.getString(4));
                member.setRole(rs.getString(6));

//                request.setAttribute("member", member);
//            ShowMember bean = dbobject.ShowMember(idEdit);
            request.setAttribute("updateuser", member);
            RequestDispatcher rd = request.getRequestDispatcher("edit-member.jsp");
            rd.forward(request, response);
//            RequestDispatcher view = request.getRequestDispatcher("edit-member.jsp");
//            view.forward(request, response);
            }
        } catch (ClassNotFoundException e) {
            out.println("Couldn't load database driver: " + e.getMessage());
        }
        catch (SQLException e) {
            out.println("SQLException caught: " + e.getMessage());
        } finally {
// Always close the database connection.
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException ignored) {
        }
    }
}
}

